from OpenGL.GL import *
from OpenGL.GLUT import *
import numpy

# Constants
X = 0
Y = 1
Z = 2

NW = 0
N = 1
NE = 2
W = 3
E = 4
SW = 5
S = 6
SE = 7

BLUE = 0
YELLOW = 1

VERSION = '0.1'

class AbstractBody(object):
	"""
	This class represents a body to be used in the map.
	It should be used as a base class for anything that
	occupies a space on the terrain.
	"""
	
	def __init__(self, size, block):
		# Size should be [X, Y].
		self.size = size
		self.top_left_block = block
		self.set_middle()
	
	def set_middle(self):
		self.middle = numpy.zeros(3)
		
		current_col = self.top_left_block
		for i in range(self.size[X]):
			current = current_col			
			for j in range(self.size[Y]):
				self.middle += current.middle
				current = current.neighbours[S]
			current_col = current_col.neighbours[E]
			
		numBlocks = self.size[X] * self.size[Y]
		self.middle /= numBlocks
	
	def render(self):
		pass

	def render_picking(self):
		"""
		This method should be called to treat picking detection,
		so rendering simpler stuff here that simulates the original
		render's volume is desired. 
		"""
		
		pass
	
	def render_selection(self):
		b_size = self.top_left_block.SIZE
		glPushMatrix()
		glTranslate(*self.middle)
		glColor(0.2, 0.8, 0.2, 0.6)
		glutSolidTorus(0.1,
					self.size[X] * b_size * 0.55, 3, 6)
		glPopMatrix()